﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace MPACore.Phonebook.Migrations
{
    public partial class Add_NewPersonAndNumber_Entity : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookEntityChanges_PhonebookEntityChangeSets_EntityChangeSetId",
                table: "PhonebookEntityChanges");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookEntityPropertyChanges_PhonebookEntityChanges_EntityChangeId",
                table: "PhonebookEntityPropertyChanges");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookFeatures_PhonebookEditions_EditionId",
                table: "PhonebookFeatures");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookOrganizationUnits_PhonebookOrganizationUnits_ParentId",
                table: "PhonebookOrganizationUnits");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookPermissions_PhonebookRoles_RoleId",
                table: "PhonebookPermissions");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookPermissions_PhonebookUsers_UserId",
                table: "PhonebookPermissions");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookRoleClaims_PhonebookRoles_RoleId",
                table: "PhonebookRoleClaims");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookRoles_PhonebookUsers_CreatorUserId",
                table: "PhonebookRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookRoles_PhonebookUsers_DeleterUserId",
                table: "PhonebookRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookRoles_PhonebookUsers_LastModifierUserId",
                table: "PhonebookRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookSettings_PhonebookUsers_UserId",
                table: "PhonebookSettings");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookTenants_PhonebookUsers_CreatorUserId",
                table: "PhonebookTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookTenants_PhonebookUsers_DeleterUserId",
                table: "PhonebookTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookTenants_PhonebookEditions_EditionId",
                table: "PhonebookTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookTenants_PhonebookUsers_LastModifierUserId",
                table: "PhonebookTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookUserClaims_PhonebookUsers_UserId",
                table: "PhonebookUserClaims");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookUserLogins_PhonebookUsers_UserId",
                table: "PhonebookUserLogins");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookUserRoles_PhonebookUsers_UserId",
                table: "PhonebookUserRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookUsers_PhonebookUsers_CreatorUserId",
                table: "PhonebookUsers");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookUsers_PhonebookUsers_DeleterUserId",
                table: "PhonebookUsers");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookUsers_PhonebookUsers_LastModifierUserId",
                table: "PhonebookUsers");

            migrationBuilder.DropForeignKey(
                name: "FK_PhonebookUserTokens_PhonebookUsers_UserId",
                table: "PhonebookUserTokens");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserTokens",
                table: "PhonebookUserTokens");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUsers",
                table: "PhonebookUsers");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserRoles",
                table: "PhonebookUserRoles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserOrganizationUnits",
                table: "PhonebookUserOrganizationUnits");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserNotifications",
                table: "PhonebookUserNotifications");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserLogins",
                table: "PhonebookUserLogins");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserLoginAttempts",
                table: "PhonebookUserLoginAttempts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserClaims",
                table: "PhonebookUserClaims");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookUserAccounts",
                table: "PhonebookUserAccounts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookTenants",
                table: "PhonebookTenants");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookTenantNotifications",
                table: "PhonebookTenantNotifications");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookSettings",
                table: "PhonebookSettings");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookRoles",
                table: "PhonebookRoles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookRoleClaims",
                table: "PhonebookRoleClaims");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookPermissions",
                table: "PhonebookPermissions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookOrganizationUnits",
                table: "PhonebookOrganizationUnits");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookNotificationSubscriptions",
                table: "PhonebookNotificationSubscriptions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookNotifications",
                table: "PhonebookNotifications");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookLanguageTexts",
                table: "PhonebookLanguageTexts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookLanguages",
                table: "PhonebookLanguages");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookFeatures",
                table: "PhonebookFeatures");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookEntityPropertyChanges",
                table: "PhonebookEntityPropertyChanges");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookEntityChangeSets",
                table: "PhonebookEntityChangeSets");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookEntityChanges",
                table: "PhonebookEntityChanges");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookEditions",
                table: "PhonebookEditions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookBackgroundJobs",
                table: "PhonebookBackgroundJobs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PhonebookAuditLogs",
                table: "PhonebookAuditLogs");

            migrationBuilder.EnsureSchema(
                name: "PB");

            migrationBuilder.RenameTable(
                name: "PhonebookUserTokens",
                newName: "PBUserTokens");

            migrationBuilder.RenameTable(
                name: "PhonebookUsers",
                newName: "PBUsers");

            migrationBuilder.RenameTable(
                name: "PhonebookUserRoles",
                newName: "PBUserRoles");

            migrationBuilder.RenameTable(
                name: "PhonebookUserOrganizationUnits",
                newName: "PBUserOrganizationUnits");

            migrationBuilder.RenameTable(
                name: "PhonebookUserNotifications",
                newName: "PBUserNotifications");

            migrationBuilder.RenameTable(
                name: "PhonebookUserLogins",
                newName: "PBUserLogins");

            migrationBuilder.RenameTable(
                name: "PhonebookUserLoginAttempts",
                newName: "PBUserLoginAttempts");

            migrationBuilder.RenameTable(
                name: "PhonebookUserClaims",
                newName: "PBUserClaims");

            migrationBuilder.RenameTable(
                name: "PhonebookUserAccounts",
                newName: "PBUserAccounts");

            migrationBuilder.RenameTable(
                name: "PhonebookTenants",
                newName: "PBTenants");

            migrationBuilder.RenameTable(
                name: "PhonebookTenantNotifications",
                newName: "PBTenantNotifications");

            migrationBuilder.RenameTable(
                name: "PhonebookSettings",
                newName: "PBSettings");

            migrationBuilder.RenameTable(
                name: "PhonebookRoles",
                newName: "PBRoles");

            migrationBuilder.RenameTable(
                name: "PhonebookRoleClaims",
                newName: "PBRoleClaims");

            migrationBuilder.RenameTable(
                name: "PhonebookPermissions",
                newName: "PBPermissions");

            migrationBuilder.RenameTable(
                name: "PhonebookOrganizationUnits",
                newName: "PBOrganizationUnits");

            migrationBuilder.RenameTable(
                name: "PhonebookNotificationSubscriptions",
                newName: "PBNotificationSubscriptions");

            migrationBuilder.RenameTable(
                name: "PhonebookNotifications",
                newName: "PBNotifications");

            migrationBuilder.RenameTable(
                name: "PhonebookLanguageTexts",
                newName: "PBLanguageTexts");

            migrationBuilder.RenameTable(
                name: "PhonebookLanguages",
                newName: "PBLanguages");

            migrationBuilder.RenameTable(
                name: "PhonebookFeatures",
                newName: "PBFeatures");

            migrationBuilder.RenameTable(
                name: "PhonebookEntityPropertyChanges",
                newName: "PBEntityPropertyChanges");

            migrationBuilder.RenameTable(
                name: "PhonebookEntityChangeSets",
                newName: "PBEntityChangeSets");

            migrationBuilder.RenameTable(
                name: "PhonebookEntityChanges",
                newName: "PBEntityChanges");

            migrationBuilder.RenameTable(
                name: "PhonebookEditions",
                newName: "PBEditions");

            migrationBuilder.RenameTable(
                name: "PhonebookBackgroundJobs",
                newName: "PBBackgroundJobs");

            migrationBuilder.RenameTable(
                name: "PhonebookAuditLogs",
                newName: "PBAuditLogs");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserTokens_TenantId_UserId",
                table: "PBUserTokens",
                newName: "IX_PBUserTokens_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserTokens_UserId",
                table: "PBUserTokens",
                newName: "IX_PBUserTokens_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUsers_TenantId_NormalizedUserName",
                table: "PBUsers",
                newName: "IX_PBUsers_TenantId_NormalizedUserName");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUsers_TenantId_NormalizedEmailAddress",
                table: "PBUsers",
                newName: "IX_PBUsers_TenantId_NormalizedEmailAddress");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUsers_LastModifierUserId",
                table: "PBUsers",
                newName: "IX_PBUsers_LastModifierUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUsers_DeleterUserId",
                table: "PBUsers",
                newName: "IX_PBUsers_DeleterUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUsers_CreatorUserId",
                table: "PBUsers",
                newName: "IX_PBUsers_CreatorUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserRoles_TenantId_UserId",
                table: "PBUserRoles",
                newName: "IX_PBUserRoles_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserRoles_TenantId_RoleId",
                table: "PBUserRoles",
                newName: "IX_PBUserRoles_TenantId_RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserRoles_UserId",
                table: "PBUserRoles",
                newName: "IX_PBUserRoles_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserOrganizationUnits_TenantId_UserId",
                table: "PBUserOrganizationUnits",
                newName: "IX_PBUserOrganizationUnits_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserOrganizationUnits_TenantId_OrganizationUnitId",
                table: "PBUserOrganizationUnits",
                newName: "IX_PBUserOrganizationUnits_TenantId_OrganizationUnitId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserNotifications_UserId_State_CreationTime",
                table: "PBUserNotifications",
                newName: "IX_PBUserNotifications_UserId_State_CreationTime");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserLogins_TenantId_LoginProvider_ProviderKey",
                table: "PBUserLogins",
                newName: "IX_PBUserLogins_TenantId_LoginProvider_ProviderKey");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserLogins_TenantId_UserId",
                table: "PBUserLogins",
                newName: "IX_PBUserLogins_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserLogins_UserId",
                table: "PBUserLogins",
                newName: "IX_PBUserLogins_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserLoginAttempts_TenancyName_UserNameOrEmailAddress_Result",
                table: "PBUserLoginAttempts",
                newName: "IX_PBUserLoginAttempts_TenancyName_UserNameOrEmailAddress_Result");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserLoginAttempts_UserId_TenantId",
                table: "PBUserLoginAttempts",
                newName: "IX_PBUserLoginAttempts_UserId_TenantId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserClaims_TenantId_ClaimType",
                table: "PBUserClaims",
                newName: "IX_PBUserClaims_TenantId_ClaimType");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserClaims_UserId",
                table: "PBUserClaims",
                newName: "IX_PBUserClaims_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserAccounts_TenantId_UserName",
                table: "PBUserAccounts",
                newName: "IX_PBUserAccounts_TenantId_UserName");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserAccounts_TenantId_UserId",
                table: "PBUserAccounts",
                newName: "IX_PBUserAccounts_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserAccounts_TenantId_EmailAddress",
                table: "PBUserAccounts",
                newName: "IX_PBUserAccounts_TenantId_EmailAddress");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserAccounts_UserName",
                table: "PBUserAccounts",
                newName: "IX_PBUserAccounts_UserName");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookUserAccounts_EmailAddress",
                table: "PBUserAccounts",
                newName: "IX_PBUserAccounts_EmailAddress");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookTenants_TenancyName",
                table: "PBTenants",
                newName: "IX_PBTenants_TenancyName");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookTenants_LastModifierUserId",
                table: "PBTenants",
                newName: "IX_PBTenants_LastModifierUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookTenants_EditionId",
                table: "PBTenants",
                newName: "IX_PBTenants_EditionId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookTenants_DeleterUserId",
                table: "PBTenants",
                newName: "IX_PBTenants_DeleterUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookTenants_CreatorUserId",
                table: "PBTenants",
                newName: "IX_PBTenants_CreatorUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookTenantNotifications_TenantId",
                table: "PBTenantNotifications",
                newName: "IX_PBTenantNotifications_TenantId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookSettings_TenantId_Name",
                table: "PBSettings",
                newName: "IX_PBSettings_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookSettings_UserId",
                table: "PBSettings",
                newName: "IX_PBSettings_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookRoles_TenantId_NormalizedName",
                table: "PBRoles",
                newName: "IX_PBRoles_TenantId_NormalizedName");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookRoles_LastModifierUserId",
                table: "PBRoles",
                newName: "IX_PBRoles_LastModifierUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookRoles_DeleterUserId",
                table: "PBRoles",
                newName: "IX_PBRoles_DeleterUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookRoles_CreatorUserId",
                table: "PBRoles",
                newName: "IX_PBRoles_CreatorUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookRoleClaims_TenantId_ClaimType",
                table: "PBRoleClaims",
                newName: "IX_PBRoleClaims_TenantId_ClaimType");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookRoleClaims_RoleId",
                table: "PBRoleClaims",
                newName: "IX_PBRoleClaims_RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookPermissions_UserId",
                table: "PBPermissions",
                newName: "IX_PBPermissions_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookPermissions_RoleId",
                table: "PBPermissions",
                newName: "IX_PBPermissions_RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookPermissions_TenantId_Name",
                table: "PBPermissions",
                newName: "IX_PBPermissions_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookOrganizationUnits_TenantId_Code",
                table: "PBOrganizationUnits",
                newName: "IX_PBOrganizationUnits_TenantId_Code");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookOrganizationUnits_ParentId",
                table: "PBOrganizationUnits",
                newName: "IX_PBOrganizationUnits_ParentId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookNotificationSubscriptions_TenantId_NotificationName_EntityTypeName_EntityId_UserId",
                table: "PBNotificationSubscriptions",
                newName: "IX_PBNotificationSubscriptions_TenantId_NotificationName_EntityTypeName_EntityId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookNotificationSubscriptions_NotificationName_EntityTypeName_EntityId_UserId",
                table: "PBNotificationSubscriptions",
                newName: "IX_PBNotificationSubscriptions_NotificationName_EntityTypeName_EntityId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookLanguageTexts_TenantId_Source_LanguageName_Key",
                table: "PBLanguageTexts",
                newName: "IX_PBLanguageTexts_TenantId_Source_LanguageName_Key");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookLanguages_TenantId_Name",
                table: "PBLanguages",
                newName: "IX_PBLanguages_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookFeatures_TenantId_Name",
                table: "PBFeatures",
                newName: "IX_PBFeatures_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookFeatures_EditionId_Name",
                table: "PBFeatures",
                newName: "IX_PBFeatures_EditionId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookEntityPropertyChanges_EntityChangeId",
                table: "PBEntityPropertyChanges",
                newName: "IX_PBEntityPropertyChanges_EntityChangeId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookEntityChangeSets_TenantId_UserId",
                table: "PBEntityChangeSets",
                newName: "IX_PBEntityChangeSets_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookEntityChangeSets_TenantId_Reason",
                table: "PBEntityChangeSets",
                newName: "IX_PBEntityChangeSets_TenantId_Reason");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookEntityChangeSets_TenantId_CreationTime",
                table: "PBEntityChangeSets",
                newName: "IX_PBEntityChangeSets_TenantId_CreationTime");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookEntityChanges_EntityTypeFullName_EntityId",
                table: "PBEntityChanges",
                newName: "IX_PBEntityChanges_EntityTypeFullName_EntityId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookEntityChanges_EntityChangeSetId",
                table: "PBEntityChanges",
                newName: "IX_PBEntityChanges_EntityChangeSetId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookBackgroundJobs_IsAbandoned_NextTryTime",
                table: "PBBackgroundJobs",
                newName: "IX_PBBackgroundJobs_IsAbandoned_NextTryTime");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookAuditLogs_TenantId_UserId",
                table: "PBAuditLogs",
                newName: "IX_PBAuditLogs_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookAuditLogs_TenantId_ExecutionTime",
                table: "PBAuditLogs",
                newName: "IX_PBAuditLogs_TenantId_ExecutionTime");

            migrationBuilder.RenameIndex(
                name: "IX_PhonebookAuditLogs_TenantId_ExecutionDuration",
                table: "PBAuditLogs",
                newName: "IX_PBAuditLogs_TenantId_ExecutionDuration");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserTokens",
                table: "PBUserTokens",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUsers",
                table: "PBUsers",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserRoles",
                table: "PBUserRoles",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserOrganizationUnits",
                table: "PBUserOrganizationUnits",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserNotifications",
                table: "PBUserNotifications",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserLogins",
                table: "PBUserLogins",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserLoginAttempts",
                table: "PBUserLoginAttempts",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserClaims",
                table: "PBUserClaims",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBUserAccounts",
                table: "PBUserAccounts",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBTenants",
                table: "PBTenants",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBTenantNotifications",
                table: "PBTenantNotifications",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBSettings",
                table: "PBSettings",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBRoles",
                table: "PBRoles",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBRoleClaims",
                table: "PBRoleClaims",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBPermissions",
                table: "PBPermissions",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBOrganizationUnits",
                table: "PBOrganizationUnits",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBNotificationSubscriptions",
                table: "PBNotificationSubscriptions",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBNotifications",
                table: "PBNotifications",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBLanguageTexts",
                table: "PBLanguageTexts",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBLanguages",
                table: "PBLanguages",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBFeatures",
                table: "PBFeatures",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBEntityPropertyChanges",
                table: "PBEntityPropertyChanges",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBEntityChangeSets",
                table: "PBEntityChangeSets",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBEntityChanges",
                table: "PBEntityChanges",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBEditions",
                table: "PBEditions",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBBackgroundJobs",
                table: "PBBackgroundJobs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PBAuditLogs",
                table: "PBAuditLogs",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "Person",
                schema: "PB",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    Name = table.Column<string>(maxLength: 50, nullable: false),
                    Email = table.Column<string>(maxLength: 80, nullable: true),
                    Address = table.Column<string>(maxLength: 200, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Person", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PhoneNumnber",
                schema: "PB",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Number = table.Column<string>(maxLength: 12, nullable: false),
                    Type = table.Column<int>(nullable: false),
                    PersonId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PhoneNumnber", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PhoneNumnber_Person_PersonId",
                        column: x => x.PersonId,
                        principalSchema: "PB",
                        principalTable: "Person",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PhoneNumnber_PersonId",
                schema: "PB",
                table: "PhoneNumnber",
                column: "PersonId");

            migrationBuilder.AddForeignKey(
                name: "FK_PBEntityChanges_PBEntityChangeSets_EntityChangeSetId",
                table: "PBEntityChanges",
                column: "EntityChangeSetId",
                principalTable: "PBEntityChangeSets",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBEntityPropertyChanges_PBEntityChanges_EntityChangeId",
                table: "PBEntityPropertyChanges",
                column: "EntityChangeId",
                principalTable: "PBEntityChanges",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBFeatures_PBEditions_EditionId",
                table: "PBFeatures",
                column: "EditionId",
                principalTable: "PBEditions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBOrganizationUnits_PBOrganizationUnits_ParentId",
                table: "PBOrganizationUnits",
                column: "ParentId",
                principalTable: "PBOrganizationUnits",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBPermissions_PBRoles_RoleId",
                table: "PBPermissions",
                column: "RoleId",
                principalTable: "PBRoles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBPermissions_PBUsers_UserId",
                table: "PBPermissions",
                column: "UserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBRoleClaims_PBRoles_RoleId",
                table: "PBRoleClaims",
                column: "RoleId",
                principalTable: "PBRoles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBRoles_PBUsers_CreatorUserId",
                table: "PBRoles",
                column: "CreatorUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBRoles_PBUsers_DeleterUserId",
                table: "PBRoles",
                column: "DeleterUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBRoles_PBUsers_LastModifierUserId",
                table: "PBRoles",
                column: "LastModifierUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBSettings_PBUsers_UserId",
                table: "PBSettings",
                column: "UserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBTenants_PBUsers_CreatorUserId",
                table: "PBTenants",
                column: "CreatorUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBTenants_PBUsers_DeleterUserId",
                table: "PBTenants",
                column: "DeleterUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBTenants_PBEditions_EditionId",
                table: "PBTenants",
                column: "EditionId",
                principalTable: "PBEditions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBTenants_PBUsers_LastModifierUserId",
                table: "PBTenants",
                column: "LastModifierUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBUserClaims_PBUsers_UserId",
                table: "PBUserClaims",
                column: "UserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBUserLogins_PBUsers_UserId",
                table: "PBUserLogins",
                column: "UserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBUserRoles_PBUsers_UserId",
                table: "PBUserRoles",
                column: "UserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PBUsers_PBUsers_CreatorUserId",
                table: "PBUsers",
                column: "CreatorUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBUsers_PBUsers_DeleterUserId",
                table: "PBUsers",
                column: "DeleterUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBUsers_PBUsers_LastModifierUserId",
                table: "PBUsers",
                column: "LastModifierUserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PBUserTokens_PBUsers_UserId",
                table: "PBUserTokens",
                column: "UserId",
                principalTable: "PBUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_PBEntityChanges_PBEntityChangeSets_EntityChangeSetId",
                table: "PBEntityChanges");

            migrationBuilder.DropForeignKey(
                name: "FK_PBEntityPropertyChanges_PBEntityChanges_EntityChangeId",
                table: "PBEntityPropertyChanges");

            migrationBuilder.DropForeignKey(
                name: "FK_PBFeatures_PBEditions_EditionId",
                table: "PBFeatures");

            migrationBuilder.DropForeignKey(
                name: "FK_PBOrganizationUnits_PBOrganizationUnits_ParentId",
                table: "PBOrganizationUnits");

            migrationBuilder.DropForeignKey(
                name: "FK_PBPermissions_PBRoles_RoleId",
                table: "PBPermissions");

            migrationBuilder.DropForeignKey(
                name: "FK_PBPermissions_PBUsers_UserId",
                table: "PBPermissions");

            migrationBuilder.DropForeignKey(
                name: "FK_PBRoleClaims_PBRoles_RoleId",
                table: "PBRoleClaims");

            migrationBuilder.DropForeignKey(
                name: "FK_PBRoles_PBUsers_CreatorUserId",
                table: "PBRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PBRoles_PBUsers_DeleterUserId",
                table: "PBRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PBRoles_PBUsers_LastModifierUserId",
                table: "PBRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PBSettings_PBUsers_UserId",
                table: "PBSettings");

            migrationBuilder.DropForeignKey(
                name: "FK_PBTenants_PBUsers_CreatorUserId",
                table: "PBTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PBTenants_PBUsers_DeleterUserId",
                table: "PBTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PBTenants_PBEditions_EditionId",
                table: "PBTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PBTenants_PBUsers_LastModifierUserId",
                table: "PBTenants");

            migrationBuilder.DropForeignKey(
                name: "FK_PBUserClaims_PBUsers_UserId",
                table: "PBUserClaims");

            migrationBuilder.DropForeignKey(
                name: "FK_PBUserLogins_PBUsers_UserId",
                table: "PBUserLogins");

            migrationBuilder.DropForeignKey(
                name: "FK_PBUserRoles_PBUsers_UserId",
                table: "PBUserRoles");

            migrationBuilder.DropForeignKey(
                name: "FK_PBUsers_PBUsers_CreatorUserId",
                table: "PBUsers");

            migrationBuilder.DropForeignKey(
                name: "FK_PBUsers_PBUsers_DeleterUserId",
                table: "PBUsers");

            migrationBuilder.DropForeignKey(
                name: "FK_PBUsers_PBUsers_LastModifierUserId",
                table: "PBUsers");

            migrationBuilder.DropForeignKey(
                name: "FK_PBUserTokens_PBUsers_UserId",
                table: "PBUserTokens");

            migrationBuilder.DropTable(
                name: "PhoneNumnber",
                schema: "PB");

            migrationBuilder.DropTable(
                name: "Person",
                schema: "PB");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserTokens",
                table: "PBUserTokens");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUsers",
                table: "PBUsers");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserRoles",
                table: "PBUserRoles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserOrganizationUnits",
                table: "PBUserOrganizationUnits");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserNotifications",
                table: "PBUserNotifications");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserLogins",
                table: "PBUserLogins");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserLoginAttempts",
                table: "PBUserLoginAttempts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserClaims",
                table: "PBUserClaims");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBUserAccounts",
                table: "PBUserAccounts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBTenants",
                table: "PBTenants");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBTenantNotifications",
                table: "PBTenantNotifications");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBSettings",
                table: "PBSettings");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBRoles",
                table: "PBRoles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBRoleClaims",
                table: "PBRoleClaims");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBPermissions",
                table: "PBPermissions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBOrganizationUnits",
                table: "PBOrganizationUnits");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBNotificationSubscriptions",
                table: "PBNotificationSubscriptions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBNotifications",
                table: "PBNotifications");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBLanguageTexts",
                table: "PBLanguageTexts");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBLanguages",
                table: "PBLanguages");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBFeatures",
                table: "PBFeatures");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBEntityPropertyChanges",
                table: "PBEntityPropertyChanges");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBEntityChangeSets",
                table: "PBEntityChangeSets");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBEntityChanges",
                table: "PBEntityChanges");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBEditions",
                table: "PBEditions");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBBackgroundJobs",
                table: "PBBackgroundJobs");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PBAuditLogs",
                table: "PBAuditLogs");

            migrationBuilder.RenameTable(
                name: "PBUserTokens",
                newName: "PhonebookUserTokens");

            migrationBuilder.RenameTable(
                name: "PBUsers",
                newName: "PhonebookUsers");

            migrationBuilder.RenameTable(
                name: "PBUserRoles",
                newName: "PhonebookUserRoles");

            migrationBuilder.RenameTable(
                name: "PBUserOrganizationUnits",
                newName: "PhonebookUserOrganizationUnits");

            migrationBuilder.RenameTable(
                name: "PBUserNotifications",
                newName: "PhonebookUserNotifications");

            migrationBuilder.RenameTable(
                name: "PBUserLogins",
                newName: "PhonebookUserLogins");

            migrationBuilder.RenameTable(
                name: "PBUserLoginAttempts",
                newName: "PhonebookUserLoginAttempts");

            migrationBuilder.RenameTable(
                name: "PBUserClaims",
                newName: "PhonebookUserClaims");

            migrationBuilder.RenameTable(
                name: "PBUserAccounts",
                newName: "PhonebookUserAccounts");

            migrationBuilder.RenameTable(
                name: "PBTenants",
                newName: "PhonebookTenants");

            migrationBuilder.RenameTable(
                name: "PBTenantNotifications",
                newName: "PhonebookTenantNotifications");

            migrationBuilder.RenameTable(
                name: "PBSettings",
                newName: "PhonebookSettings");

            migrationBuilder.RenameTable(
                name: "PBRoles",
                newName: "PhonebookRoles");

            migrationBuilder.RenameTable(
                name: "PBRoleClaims",
                newName: "PhonebookRoleClaims");

            migrationBuilder.RenameTable(
                name: "PBPermissions",
                newName: "PhonebookPermissions");

            migrationBuilder.RenameTable(
                name: "PBOrganizationUnits",
                newName: "PhonebookOrganizationUnits");

            migrationBuilder.RenameTable(
                name: "PBNotificationSubscriptions",
                newName: "PhonebookNotificationSubscriptions");

            migrationBuilder.RenameTable(
                name: "PBNotifications",
                newName: "PhonebookNotifications");

            migrationBuilder.RenameTable(
                name: "PBLanguageTexts",
                newName: "PhonebookLanguageTexts");

            migrationBuilder.RenameTable(
                name: "PBLanguages",
                newName: "PhonebookLanguages");

            migrationBuilder.RenameTable(
                name: "PBFeatures",
                newName: "PhonebookFeatures");

            migrationBuilder.RenameTable(
                name: "PBEntityPropertyChanges",
                newName: "PhonebookEntityPropertyChanges");

            migrationBuilder.RenameTable(
                name: "PBEntityChangeSets",
                newName: "PhonebookEntityChangeSets");

            migrationBuilder.RenameTable(
                name: "PBEntityChanges",
                newName: "PhonebookEntityChanges");

            migrationBuilder.RenameTable(
                name: "PBEditions",
                newName: "PhonebookEditions");

            migrationBuilder.RenameTable(
                name: "PBBackgroundJobs",
                newName: "PhonebookBackgroundJobs");

            migrationBuilder.RenameTable(
                name: "PBAuditLogs",
                newName: "PhonebookAuditLogs");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserTokens_TenantId_UserId",
                table: "PhonebookUserTokens",
                newName: "IX_PhonebookUserTokens_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserTokens_UserId",
                table: "PhonebookUserTokens",
                newName: "IX_PhonebookUserTokens_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUsers_TenantId_NormalizedUserName",
                table: "PhonebookUsers",
                newName: "IX_PhonebookUsers_TenantId_NormalizedUserName");

            migrationBuilder.RenameIndex(
                name: "IX_PBUsers_TenantId_NormalizedEmailAddress",
                table: "PhonebookUsers",
                newName: "IX_PhonebookUsers_TenantId_NormalizedEmailAddress");

            migrationBuilder.RenameIndex(
                name: "IX_PBUsers_LastModifierUserId",
                table: "PhonebookUsers",
                newName: "IX_PhonebookUsers_LastModifierUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUsers_DeleterUserId",
                table: "PhonebookUsers",
                newName: "IX_PhonebookUsers_DeleterUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUsers_CreatorUserId",
                table: "PhonebookUsers",
                newName: "IX_PhonebookUsers_CreatorUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserRoles_TenantId_UserId",
                table: "PhonebookUserRoles",
                newName: "IX_PhonebookUserRoles_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserRoles_TenantId_RoleId",
                table: "PhonebookUserRoles",
                newName: "IX_PhonebookUserRoles_TenantId_RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserRoles_UserId",
                table: "PhonebookUserRoles",
                newName: "IX_PhonebookUserRoles_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserOrganizationUnits_TenantId_UserId",
                table: "PhonebookUserOrganizationUnits",
                newName: "IX_PhonebookUserOrganizationUnits_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserOrganizationUnits_TenantId_OrganizationUnitId",
                table: "PhonebookUserOrganizationUnits",
                newName: "IX_PhonebookUserOrganizationUnits_TenantId_OrganizationUnitId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserNotifications_UserId_State_CreationTime",
                table: "PhonebookUserNotifications",
                newName: "IX_PhonebookUserNotifications_UserId_State_CreationTime");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserLogins_TenantId_LoginProvider_ProviderKey",
                table: "PhonebookUserLogins",
                newName: "IX_PhonebookUserLogins_TenantId_LoginProvider_ProviderKey");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserLogins_TenantId_UserId",
                table: "PhonebookUserLogins",
                newName: "IX_PhonebookUserLogins_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserLogins_UserId",
                table: "PhonebookUserLogins",
                newName: "IX_PhonebookUserLogins_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserLoginAttempts_TenancyName_UserNameOrEmailAddress_Result",
                table: "PhonebookUserLoginAttempts",
                newName: "IX_PhonebookUserLoginAttempts_TenancyName_UserNameOrEmailAddress_Result");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserLoginAttempts_UserId_TenantId",
                table: "PhonebookUserLoginAttempts",
                newName: "IX_PhonebookUserLoginAttempts_UserId_TenantId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserClaims_TenantId_ClaimType",
                table: "PhonebookUserClaims",
                newName: "IX_PhonebookUserClaims_TenantId_ClaimType");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserClaims_UserId",
                table: "PhonebookUserClaims",
                newName: "IX_PhonebookUserClaims_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserAccounts_TenantId_UserName",
                table: "PhonebookUserAccounts",
                newName: "IX_PhonebookUserAccounts_TenantId_UserName");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserAccounts_TenantId_UserId",
                table: "PhonebookUserAccounts",
                newName: "IX_PhonebookUserAccounts_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserAccounts_TenantId_EmailAddress",
                table: "PhonebookUserAccounts",
                newName: "IX_PhonebookUserAccounts_TenantId_EmailAddress");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserAccounts_UserName",
                table: "PhonebookUserAccounts",
                newName: "IX_PhonebookUserAccounts_UserName");

            migrationBuilder.RenameIndex(
                name: "IX_PBUserAccounts_EmailAddress",
                table: "PhonebookUserAccounts",
                newName: "IX_PhonebookUserAccounts_EmailAddress");

            migrationBuilder.RenameIndex(
                name: "IX_PBTenants_TenancyName",
                table: "PhonebookTenants",
                newName: "IX_PhonebookTenants_TenancyName");

            migrationBuilder.RenameIndex(
                name: "IX_PBTenants_LastModifierUserId",
                table: "PhonebookTenants",
                newName: "IX_PhonebookTenants_LastModifierUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBTenants_EditionId",
                table: "PhonebookTenants",
                newName: "IX_PhonebookTenants_EditionId");

            migrationBuilder.RenameIndex(
                name: "IX_PBTenants_DeleterUserId",
                table: "PhonebookTenants",
                newName: "IX_PhonebookTenants_DeleterUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBTenants_CreatorUserId",
                table: "PhonebookTenants",
                newName: "IX_PhonebookTenants_CreatorUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBTenantNotifications_TenantId",
                table: "PhonebookTenantNotifications",
                newName: "IX_PhonebookTenantNotifications_TenantId");

            migrationBuilder.RenameIndex(
                name: "IX_PBSettings_TenantId_Name",
                table: "PhonebookSettings",
                newName: "IX_PhonebookSettings_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PBSettings_UserId",
                table: "PhonebookSettings",
                newName: "IX_PhonebookSettings_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBRoles_TenantId_NormalizedName",
                table: "PhonebookRoles",
                newName: "IX_PhonebookRoles_TenantId_NormalizedName");

            migrationBuilder.RenameIndex(
                name: "IX_PBRoles_LastModifierUserId",
                table: "PhonebookRoles",
                newName: "IX_PhonebookRoles_LastModifierUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBRoles_DeleterUserId",
                table: "PhonebookRoles",
                newName: "IX_PhonebookRoles_DeleterUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBRoles_CreatorUserId",
                table: "PhonebookRoles",
                newName: "IX_PhonebookRoles_CreatorUserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBRoleClaims_TenantId_ClaimType",
                table: "PhonebookRoleClaims",
                newName: "IX_PhonebookRoleClaims_TenantId_ClaimType");

            migrationBuilder.RenameIndex(
                name: "IX_PBRoleClaims_RoleId",
                table: "PhonebookRoleClaims",
                newName: "IX_PhonebookRoleClaims_RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_PBPermissions_UserId",
                table: "PhonebookPermissions",
                newName: "IX_PhonebookPermissions_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBPermissions_RoleId",
                table: "PhonebookPermissions",
                newName: "IX_PhonebookPermissions_RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_PBPermissions_TenantId_Name",
                table: "PhonebookPermissions",
                newName: "IX_PhonebookPermissions_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PBOrganizationUnits_TenantId_Code",
                table: "PhonebookOrganizationUnits",
                newName: "IX_PhonebookOrganizationUnits_TenantId_Code");

            migrationBuilder.RenameIndex(
                name: "IX_PBOrganizationUnits_ParentId",
                table: "PhonebookOrganizationUnits",
                newName: "IX_PhonebookOrganizationUnits_ParentId");

            migrationBuilder.RenameIndex(
                name: "IX_PBNotificationSubscriptions_TenantId_NotificationName_EntityTypeName_EntityId_UserId",
                table: "PhonebookNotificationSubscriptions",
                newName: "IX_PhonebookNotificationSubscriptions_TenantId_NotificationName_EntityTypeName_EntityId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBNotificationSubscriptions_NotificationName_EntityTypeName_EntityId_UserId",
                table: "PhonebookNotificationSubscriptions",
                newName: "IX_PhonebookNotificationSubscriptions_NotificationName_EntityTypeName_EntityId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBLanguageTexts_TenantId_Source_LanguageName_Key",
                table: "PhonebookLanguageTexts",
                newName: "IX_PhonebookLanguageTexts_TenantId_Source_LanguageName_Key");

            migrationBuilder.RenameIndex(
                name: "IX_PBLanguages_TenantId_Name",
                table: "PhonebookLanguages",
                newName: "IX_PhonebookLanguages_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PBFeatures_TenantId_Name",
                table: "PhonebookFeatures",
                newName: "IX_PhonebookFeatures_TenantId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PBFeatures_EditionId_Name",
                table: "PhonebookFeatures",
                newName: "IX_PhonebookFeatures_EditionId_Name");

            migrationBuilder.RenameIndex(
                name: "IX_PBEntityPropertyChanges_EntityChangeId",
                table: "PhonebookEntityPropertyChanges",
                newName: "IX_PhonebookEntityPropertyChanges_EntityChangeId");

            migrationBuilder.RenameIndex(
                name: "IX_PBEntityChangeSets_TenantId_UserId",
                table: "PhonebookEntityChangeSets",
                newName: "IX_PhonebookEntityChangeSets_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBEntityChangeSets_TenantId_Reason",
                table: "PhonebookEntityChangeSets",
                newName: "IX_PhonebookEntityChangeSets_TenantId_Reason");

            migrationBuilder.RenameIndex(
                name: "IX_PBEntityChangeSets_TenantId_CreationTime",
                table: "PhonebookEntityChangeSets",
                newName: "IX_PhonebookEntityChangeSets_TenantId_CreationTime");

            migrationBuilder.RenameIndex(
                name: "IX_PBEntityChanges_EntityTypeFullName_EntityId",
                table: "PhonebookEntityChanges",
                newName: "IX_PhonebookEntityChanges_EntityTypeFullName_EntityId");

            migrationBuilder.RenameIndex(
                name: "IX_PBEntityChanges_EntityChangeSetId",
                table: "PhonebookEntityChanges",
                newName: "IX_PhonebookEntityChanges_EntityChangeSetId");

            migrationBuilder.RenameIndex(
                name: "IX_PBBackgroundJobs_IsAbandoned_NextTryTime",
                table: "PhonebookBackgroundJobs",
                newName: "IX_PhonebookBackgroundJobs_IsAbandoned_NextTryTime");

            migrationBuilder.RenameIndex(
                name: "IX_PBAuditLogs_TenantId_UserId",
                table: "PhonebookAuditLogs",
                newName: "IX_PhonebookAuditLogs_TenantId_UserId");

            migrationBuilder.RenameIndex(
                name: "IX_PBAuditLogs_TenantId_ExecutionTime",
                table: "PhonebookAuditLogs",
                newName: "IX_PhonebookAuditLogs_TenantId_ExecutionTime");

            migrationBuilder.RenameIndex(
                name: "IX_PBAuditLogs_TenantId_ExecutionDuration",
                table: "PhonebookAuditLogs",
                newName: "IX_PhonebookAuditLogs_TenantId_ExecutionDuration");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserTokens",
                table: "PhonebookUserTokens",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUsers",
                table: "PhonebookUsers",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserRoles",
                table: "PhonebookUserRoles",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserOrganizationUnits",
                table: "PhonebookUserOrganizationUnits",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserNotifications",
                table: "PhonebookUserNotifications",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserLogins",
                table: "PhonebookUserLogins",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserLoginAttempts",
                table: "PhonebookUserLoginAttempts",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserClaims",
                table: "PhonebookUserClaims",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookUserAccounts",
                table: "PhonebookUserAccounts",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookTenants",
                table: "PhonebookTenants",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookTenantNotifications",
                table: "PhonebookTenantNotifications",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookSettings",
                table: "PhonebookSettings",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookRoles",
                table: "PhonebookRoles",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookRoleClaims",
                table: "PhonebookRoleClaims",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookPermissions",
                table: "PhonebookPermissions",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookOrganizationUnits",
                table: "PhonebookOrganizationUnits",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookNotificationSubscriptions",
                table: "PhonebookNotificationSubscriptions",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookNotifications",
                table: "PhonebookNotifications",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookLanguageTexts",
                table: "PhonebookLanguageTexts",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookLanguages",
                table: "PhonebookLanguages",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookFeatures",
                table: "PhonebookFeatures",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookEntityPropertyChanges",
                table: "PhonebookEntityPropertyChanges",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookEntityChangeSets",
                table: "PhonebookEntityChangeSets",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookEntityChanges",
                table: "PhonebookEntityChanges",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookEditions",
                table: "PhonebookEditions",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookBackgroundJobs",
                table: "PhonebookBackgroundJobs",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PhonebookAuditLogs",
                table: "PhonebookAuditLogs",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookEntityChanges_PhonebookEntityChangeSets_EntityChangeSetId",
                table: "PhonebookEntityChanges",
                column: "EntityChangeSetId",
                principalTable: "PhonebookEntityChangeSets",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookEntityPropertyChanges_PhonebookEntityChanges_EntityChangeId",
                table: "PhonebookEntityPropertyChanges",
                column: "EntityChangeId",
                principalTable: "PhonebookEntityChanges",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookFeatures_PhonebookEditions_EditionId",
                table: "PhonebookFeatures",
                column: "EditionId",
                principalTable: "PhonebookEditions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookOrganizationUnits_PhonebookOrganizationUnits_ParentId",
                table: "PhonebookOrganizationUnits",
                column: "ParentId",
                principalTable: "PhonebookOrganizationUnits",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookPermissions_PhonebookRoles_RoleId",
                table: "PhonebookPermissions",
                column: "RoleId",
                principalTable: "PhonebookRoles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookPermissions_PhonebookUsers_UserId",
                table: "PhonebookPermissions",
                column: "UserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookRoleClaims_PhonebookRoles_RoleId",
                table: "PhonebookRoleClaims",
                column: "RoleId",
                principalTable: "PhonebookRoles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookRoles_PhonebookUsers_CreatorUserId",
                table: "PhonebookRoles",
                column: "CreatorUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookRoles_PhonebookUsers_DeleterUserId",
                table: "PhonebookRoles",
                column: "DeleterUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookRoles_PhonebookUsers_LastModifierUserId",
                table: "PhonebookRoles",
                column: "LastModifierUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookSettings_PhonebookUsers_UserId",
                table: "PhonebookSettings",
                column: "UserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookTenants_PhonebookUsers_CreatorUserId",
                table: "PhonebookTenants",
                column: "CreatorUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookTenants_PhonebookUsers_DeleterUserId",
                table: "PhonebookTenants",
                column: "DeleterUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookTenants_PhonebookEditions_EditionId",
                table: "PhonebookTenants",
                column: "EditionId",
                principalTable: "PhonebookEditions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookTenants_PhonebookUsers_LastModifierUserId",
                table: "PhonebookTenants",
                column: "LastModifierUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookUserClaims_PhonebookUsers_UserId",
                table: "PhonebookUserClaims",
                column: "UserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookUserLogins_PhonebookUsers_UserId",
                table: "PhonebookUserLogins",
                column: "UserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookUserRoles_PhonebookUsers_UserId",
                table: "PhonebookUserRoles",
                column: "UserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookUsers_PhonebookUsers_CreatorUserId",
                table: "PhonebookUsers",
                column: "CreatorUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookUsers_PhonebookUsers_DeleterUserId",
                table: "PhonebookUsers",
                column: "DeleterUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookUsers_PhonebookUsers_LastModifierUserId",
                table: "PhonebookUsers",
                column: "LastModifierUserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PhonebookUserTokens_PhonebookUsers_UserId",
                table: "PhonebookUserTokens",
                column: "UserId",
                principalTable: "PhonebookUsers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
